#include<thread>
#include<iostream>
#include<mutex>
#include<condition_variable>
using namespace std;




int main()
{
	mutex mtx;
	condition_variable cv;
	bool flag = true;
	static int j = 1;

	thread t1([&] {
		while (j < 100)
		{
			std::unique_lock<mutex> guard(mtx);
			cv.wait(guard, [&] {
				return flag;
				});
			cout << "func1: " << j << endl;
			j += 1;
			flag = false;
			cv.notify_one();
		}

		});
	thread t2([&] {
		while (j < 100)
		{
			std::unique_lock<mutex> guard(mtx);
			cv.wait(guard, [&] {
				return !flag;
				});
			cout << "func2: " << j << endl;
			j += 1;
			flag = true;
			cv.notify_one();
		}
		}
	);
	t1.join();
	t2.join();
	return 0;
}